const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{
			label: '名称',
			prop: 'projectName',
		},
		{
			label: '申请补贴类别',
			prop: 'subsidyType',
			propName: 'subsidyTypeLabel',
			type: 'remoteSelect',
			api: 'getDictItemList',
			code: 'SUBSIDY_TYPE',
		},
		{
			label: '生效时间',
			prop: 'templateNo',
			showOverflowTooltip: false,
			width: 200,
		},
		{
			label: '状态',
			prop: 'projectEnable',
			custome: 'tag',
			dicData: [
				{ label: '开启', value: 1, style: { color: '#00A870', background: '#C8FFB1' } },
				{ label: '关闭', value: 0, style: { color: '#FA3E3E', background: '#FFC4B1' } },
			],
		},
		{
			label: '选择填报机构数',
			prop: 'organizationSize',
		},
		{
			label: '创建人',
			prop: 'createUserName',
		},
		{
			label: '创建时间',
			prop: 'createTime',
		},
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'right',
	labelWidth: '100px',
	column: [
		{
			label: '名 称',
			prop: 'projectName',
			type: 'input',
			span: 8,
		},
		{
			label: '申请补贴类别',
			prop: 'subsidyType',
			propName: 'subsidyTypeLabel',
			type: 'remoteSelect',
			api: 'getDictItemList',
			code: 'SUBSIDY_TYPE',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '状态',
			prop: 'projectEnable',
			type: 'select',
			dicData: [
				{ label: '开启', value: 1 },
				{ label: '关闭', value: 0 },
			],
			span: 8,
		},
		{
			label: '创建人',
			prop: 'createUserName',
			type: 'input',
			span: 8,
		},
		{
			label: '创建时间',
			prop: 'createTimeBetween',
			type: 'dateBetween',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			span: 8,
		},
	],
}
export const detailConfig: any = {
	inline: false,
	labelPosition: 'left',
	labelWidth: '200px',
	showBtn: false,
	column: [
		{
			label: '名称',
			prop: 'projectName',
			span: 24,
		},
		{
			label: '选择申请补贴类型',
			prop: 'subsidyType',
			propName: 'subsidyTypeLabel',
			type: 'remoteSelect',
			api: 'getDictItemList',
			code: 'SUBSIDY_TYPE',
			filterKey: 'value',
			multiple: false,
			span: 24,
		},
		{
			label: '项目日期范围',
			prop: 'startToEnd',
			span: 24,
		},
		{
			label: '状态',
			prop: 'projectEnable',
			type: 'radio',
			dicData: [
				{ label: '开启', value: 1 },
				{ label: '关闭', value: 0 },
			],
			span: 24,
		},
		{
			label: '选择填报的养老服务组织',
			prop: 'organizationIdsLabel',
			span: 24,
		},
		{
			label: '选择申请配置信息',
			prop: 'subsidyApplyConfigName',
			span: 24,
		},
		{
			label: '是否开启自动申请',
			prop: 'autoApplyFlag',
			type: 'radio',
			dicData: [
				{ label: '开启', value: 1 },
				{ label: '关闭', value: 0 },
			],
			span: 24,
		},
		{
			label: '自动申请时限',
			prop: 'autoLimitDay',
			value: 0,
			display: false,
			type: 'input',
			span: 24,
		},
		{
			label: '选择审批配置信息',
			prop: 'workflowName',
			span: 24,
		},
		{
			label: '表单预览',
			prop: 'formPreview',
			span: 24,
		},
	],
}

const api = {
	index: 'view_ofsSubsidyProject_page',
	add: 'view_ofsSubsidyProject_add',
	edit: 'view_ofsSubsidyProject_edit',
	delete: 'view_ofsSubsidyProject_del',
}
export const baseConfig: any = {
	pageName: '项目管理',
	addLabel: '创建项目',
	dictcodes: ['SUBSIDY_TYPE'],
	rowKey: 'id',
	tipLabel: 'projectName',
	api: api,
	auth: {
		...api,
	},

	menuBtn: [
		{
			icon: 'editor',
			label: '查看',
			type: 'primary',
			operate: 'Detail',
			auth: '',
			text: true,
			show: true,
		},
		{
			icon: 'editor',
			label: '编辑',
			type: 'info',
			operate: 'edit',
			auth: api.edit,
			text: true,
			show: true,
		},
		{
			icon: 'editor',
			label: '申请配置',
			type: 'info',
			operate: 'apply',
			auth: '',
			text: true,
			show: true,
		},
		{
			icon: 'editor',
			label: '审批配置',
			type: 'info',
			operate: 'approval',
			auth: '',
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: api.delete,
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '65%',
	},
	searchConfig,
	tableConfig,
	detailConfig,
	beforeOnLoadFormate: async (query) => {
		return new Promise((resolve, reject) => {
			if (query.createTimeBetween) {
				query.createTimeBetween = query.createTimeBetween.replace(/(00:00:00)$/, '23:59:59')
			}
			resolve({
				...query,
			})
		})
	},
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			let organizationIdsLabel = ''
			if (item.organizationJson) {
				let organizationIdsLabelList = JSON.parse(item.organizationJson).map((el) => {
					return el.label
				})
				organizationIdsLabel = organizationIdsLabelList.join(',')
			}
			let startToEnd = item.projectStartDate + '~' + item.projectEndDate
			return {
				...item,
				startToEnd,
				organizationIdsLabel,
			}
		})
		return Promise.resolve(Object.freeze(tableData))
	},
}
